package org.example.easybuy.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.example.easybuy.dao.CategoryDao;
import org.example.easybuy.entity.Category;
import org.example.easybuy.service.CategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service
public class CategoryServiceImpl implements CategoryService {
    @Autowired
    private CategoryDao categoryDao;

    @Override
    public PageInfo<Category> getCategoryPageInfo(Map<String,Object> params) {
        PageHelper.startPage(params);
        List<Category> list=categoryDao.selectByPage(params);
        return new PageInfo<>(list,3);
    }

    @Override
    public List<Category> selectByType(int type) {
        return categoryDao.selectByType(type);
    }

    @Override
    public List<Category> selectListById(int id) {
        return categoryDao.selectListById(id);
    }

    @Override
    public Category checkCateName(Map<String, Object> params) {
        return categoryDao.checkCateName(params);
    }

    @Override
    public boolean addCategory(Map<String, Object> params) {
        return categoryDao.addCategory(params)==1;
    }

    @Override
    public Category getUpdateCategory(String id, int type) {
        return categoryDao.getUpdateCategory(id,type);
    }

    @Override
    public int selectCateCount(int type, int id) {
        return categoryDao.selectCateCount(type,id);
    }

    @Override
    public boolean deleteCate(int id) {
        return categoryDao.deleteCate(id)==1;
    }

    @Override
    public boolean updateCategory(Map<String, Object> map) {
        return categoryDao.updateCategory(map)==1;
    }

    @Override
    public int selectTypeById(int id) {
        return categoryDao.selectTypeById(id);
    }
}
